package com.mitake.nick.example.socket;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientEx {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if(args.length < 1){
			System.out.println("you forget the name of the server!");
			System.exit(1);
		}
		
		Socket socket;
		String str = "test123.net";
		String len;
		InputStream is;
		OutputStream os;
		DataInputStream dis;
		PrintStream ps;
		
		try {
			socket = new Socket(args[0], 4321);
			
			System.out.println("client ok");
			System.out.println("*******************************************");
			System.out.println("");
			
			is = socket.getInputStream();
			os = socket.getOutputStream();
			dis = new DataInputStream(is);
			ps = new PrintStream(os);
			DataInputStream in = new DataInputStream(System.in);
			
			while(true){
				System.out.print("you say:");
				str = in.readLine();
				ps.println(str);
				
				if("bye".equals(str.trim())){
					break;
				}
			}
			
			dis.close();
			ps.close();
			is.close();
			os.close();
			socket.close();
			
		} catch (Exception e) {
			System.out.println("Error:"+ e);
		}
	}

}
